#ifndef BREADCRUMBSSYNC_H
#define BREADCRUMBSSYNC_H

#include "controls/rotatingwidget.h"

class GPS_track;
class FTLabel;
class FTComboBox;
class FTPushButton;
class OauthManager;
class FTList;
class FTTextArea;
class FTCheckBox;
class FTHelpWidget;

struct searched_track
{
    QString id;
    QDateTime start_time;
    QDateTime end_time;
    QString name;
    QString description;
    double distance;
    double lat;
    double lon;
    double elevation_gain;
    int difficulty;
    int track_rating;
};

class BreadcrumbsSync : public RotatingWidget
{
    Q_OBJECT
public:
    enum mode { upload_track, download_track, not_initialized };

    explicit BreadcrumbsSync();
    ~BreadcrumbsSync();

    void setUploadTrack(const GPS_track* );
    GPS_track* fetchDownloadedTrack();

    BreadcrumbsSync::mode currentMode() const;

signals:
    void trackUploaded();
    void trackDownloaded();

public slots:
    void setMode( BreadcrumbsSync::mode );

private slots:
    void forceReload();

private:
    BreadcrumbsSync::mode _currentMode;
    void buildUpload();
    void buildDownload();
    void buildNotConfigured();

    QStackedWidget* pages;
    OauthManager* oauth;

    void loadActivities();
    void populateActivities();

    QString selectedBundleId();
    QString selectedActivityId();

    QLayout* createHorizontal();
    QLayout* createVertical();

private: // Upload tracks...

    const GPS_track* track;
    QWidget* uploadPage;
    FTPushButton* upload_reloadButton;
    FTLabel* upload_activityLabel;
    FTComboBox* upload_activityCombo;
    FTLabel* upload_bundleLabel;
    FTComboBox* upload_bundleCombo;
    FTPushButton* upload_newBundleButton;
    FTPushButton* uploadButton;
    FTCheckBox* uploadPublicCheck;
    FTHelpWidget* uploadHelp;
    void update_populateBundles();


private slots: // slots for track update
    // When activities has been selected
    void upload_activitySelected(QString);
    // When bundle selected
    void upload_bundleSelected(QString);
    // Create new bundle
    void upload_createNewBundle();
    // Upload the track...
    void uploadTrack();


private: //Download tracks...

    QWidget* downloadPage;
    GPS_track* downloadedTrack;
    FTPushButton* download_searchButton;
    FTPushButton* download_fetchButton;
    FTPushButton* download_reloadButton;
    FTLabel* download_activityLabel;
    FTComboBox* download_activityCombo;
    FTLabel* download_numTracksLabel;
    FTComboBox* download_numTracksCombo;
    FTLabel* download_distanceLabel;
    FTComboBox* download_distanceCombo;
    FTComboBox* download_fetchedCombo;
    QList<FTLabel*> download_labels;
    QList<searched_track*> download_fetched;
    FTHelpWidget* downloadHelp;
    void download_populateFetched();
    searched_track* download_selectedTrack();

private slots: // Download slots...
    // For search button
    void download_searchTracks();
    // Fetch the track...
    void download_fetchTrack();
    // select track
    void download_displayTrack();

private: // Not configured
    FTTextArea* notConfiguredLabel;

private: // list static stuff
    static QMap<QString, QString> list_activities;
    static QMap<QString, QMap<QString,QString> > list_bundles;
    static bool loaded;
};

#endif // BREADCRUMBSSYNC_H
